		TITLE	REOPEN - Copyright (C) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	IO_STRUC
		INCLUDE	WIN32DEF

		PUBLIC	REOPEN_OUTPUT


		.DATA

		EXTERNDEF	SHARE_ANDER:BYTE,ASCIZ:BYTE

		EXTERNDEF	_FILE_LIST_GARRAY:STD_PTR_S


		.CODE	PASS2_TEXT

		EXTERNDEF	GET_OUTPUT_DEVICE:PROC,MOVE_FN_TO_ASCIZ:PROC,_recover_handle:PROC,_err_file_list_abort:proc

		EXTERNDEF	CANT_REOPEN_ERR:ABS


REOPEN_OUTPUT	PROC
		;
		;FILE ALREADY EXISTS, JUST RESTORE POINTERS
		;
		;EAX IS OUTFILE_STRUCT
		;
		;RETURN EAX = MYO_STRUCT
		;
		PUSH	ESI
		MOV	ESI,EAX
		ASSUME	ESI:PTR OUTFILE_STRUCT

		CALL	GET_OUTPUT_DEVICE
		ASSUME	EAX:PTR MYO_STRUCT

		MOV	ECX,[ESI]._OF_PHYS_ADDR
		MOV	EDX,[ESI]._OF_FILE_LIST_GINDEX

		MOV	[EAX].MYO_PHYS_ADDR,ECX
		MOV	ECX,[ESI]._OF_HANDLE

		MOV	[EAX].MYO_FILE_LIST_GINDEX,EDX
		TEST	ECX,ECX

		MOV	[EAX].MYO_HANDLE,ECX
		JZ	L5$

		POP	ESI

		RET

L5$:
		PUSH	EBX
		MOV	EBX,EAX
		ASSUME	EBX:PTR MYO_STRUCT
		;
		;REALLY NEED TO REOPEN IT...
		;
		CONVERT	EDI,EDX,_FILE_LIST_GARRAY
		ASSUME	EDI:PTR FILE_LIST_STRUCT

L55$:
		PUSH	0			;ATTRIBUTE FILE
		PUSH	FILE_FLAG_RANDOM_ACCESS

		PUSH	OPEN_EXISTING
		PUSH	0			;SECURITY ATTRIBUTES

		PUSH	0			;DENY ALL
		PUSH	GENERIC_WRITE		;WRITE ACCESS

		LEA	EDX,[EDI].FILE_LIST_NFN.NFN_TEXT

		PUSH	EDX			;ASCIZ FILENAME
		CALL	CreateFile

		CMP	EAX,INVALID_HANDLE_VALUE
		JNZ	L6$

		CALL	_recover_handle
		OR	EAX,EAX
		JZ	L55$

		MOV	AL,CANT_REOPEN_ERR

		MOV	ECX,[EBX].MYO_FILE_LIST_GINDEX

		push	ECX
		push	EAX
		call	_err_file_list_abort
		add	ESP,8

L6$:
		MOV	ECX,[ESI]._OF_PHYS_ADDR
		MOV	[EBX].MYO_HANDLE,EAX

		MOV	[ESI]._OF_HANDLE,EAX
		POP	EBX

		PUSH	EAX		;SAVE HANDLE
		PUSH	FILE_BEGIN

		PUSH	0		;DISTANCE HIGH
		PUSH	ECX		;DISTANCE LOW

		PUSH	EAX		;HANDLE
		CALL	SetFilePointer

		POPM	EAX,ESI

		RET

REOPEN_OUTPUT	ENDP


		END

